unit AEStack; interface uses Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils,Resources, Errors, Palettes, LowMem, AppleEvents,AEObjects, AERegistry, Errors, Math,Background,Analysis,Camera,Stacks,Projection, globals, Utilities, Edit, Filters, Graphics, Camera, PlugIns, Macros1, Macros2, File1, File2, Lut, Text, User, Msc, AEUtility, AEWIndow, AEPicture; function StackEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; inCommand: OSType):OSerr; FUNCTION FindStackAccessor (desiredClass: DescType; containerToken: AEDesc; containerClass: DescType; keyForm: DescType; keyData: AEDesc; VAR outToken: AEDesc; theRefCon: LongInt): OSErr; implementation { *************************************************************************************** Handles AppleEvents sent to a window that holds a picture. *************************************************************************************** } function StackEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; inCommand: OSType):OSerr; VAR theError,ignoreErr:OSErr; theWindow:WindowPtr; AutoSelectAll:Boolean; OldPicNum, NewPicNum: integer; theString, theName:str255; theShortValue, sStart, sEnd:integer; theExtendedValue:extended; answer, on:Boolean; theEnum:DescType; lastPt, pt:Point; fwidth, i, pic1, pic2, wn, old: integer; theLongValue:LongInt; xAdd, xMul: extended; begin if inToken^.name = 'rang' then begin inToken^.name := '----'; for wn := inToken^.thru downto inToken^.index do begin inToken^.container := LongInt(PicWindow[wn]); StackEvents := StackEvents(inAppleEvent, reply, inToken, inCommand); end; exit(StackEvents); end; theWindow := WindowPtr(inToken^.container); theError := noErr; StackEvents := noErr; if (theWindow = nil) or (info^.StackInfo = nil) then begin StackEvents := PictureEvents(inAppleEvent, reply, inToken, inCommand); exit(StackEvents); end; if inCommand = 'Inst' then answer := AddSlice(true) else if inCommand = 'delo' then DeleteSlice else if inCommand = 'AvgS' then AverageSlices else if inCommand = 'iRGB' then begin theError := GetAEBoolean(inAppleEvent,'dith',DitherColor); theError := GetAEEnum(inAppleEvent, 'mode', theEnum); if theEnum = 'xLUT' then RGBLut := ExistingLUT else if theEnum = 'sLUT' then RGBLut := SystemLUT else RGBLut := CustomLUT; ConvertRGBToEightBitColor(false); end else if inCommand = 'Proj' then begin with info^.StackInfo^ do begin if SliceSpacing <= 0.0 then SliceSpacing := 1.0; if DensitySlicing then with info^ do begin TransparencyLower := SliceStart; TransparencyUpper := SliceEnd; end; DoProjection; end; end else if inCommand = 'ReSl' then Reslice else theError := PictureEvents(inAppleEvent, reply, inToken, inCommand); StackEvents := theError; end; FUNCTION FindStackAccessor (desiredClass: DescType; containerToken: AEDesc; containerClass: DescType; keyForm: DescType; keyData: AEDesc; VAR outToken: AEDesc; theRefCon: LongInt): OSErr; VAR theError: OSErr; theName,theWindowName:Str255; theWindow: WindowPtr; theWindowN: integer; iLoop: integer; theID: LongInt; theInfo: InfoPtr; theEnum: DescType; BEGIN theWindow := nil; IF keyForm = formName THEN BEGIN theError := StringFromDesc(keyData, theName); if (theError = noErr) then for iLoop := 1 to nPics do BEGIN GetWTitle(PicWindow[iLoop], theWindowName); theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) and (IUEqualString(theWindowName, theName) = 0) then theWindow := PicWindow[iLoop]; END; if theWindow = nil then begin MakeNewTokenDesc(theName, 'Stak', outToken); FindStackAccessor := noErr; exit(FindStackAccessor); end; END ELSE IF keyForm = formAbsolutePosition THEN begin theError := ShortFromDesc(keyData, theWindowN); theID := 0; IF theError = noErr then if (theWindowN < 1) then {oops, passed an ID rather than index } for iLoop := 1 to nPics do begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then begin theID := theID + 1; if theID = theWindowN then theWindow := PicWindow[iLoop]; end end else if theWindowN <= nPics then theWindow := PicWindow[theWindowN] end ELSE IF keyForm = formRelativePosition THEN begin theError := EnumFromDesc(keyData, theEnum); if (theError = noErr) then begin iLoop := info^.PicNum; if theEnum = kAENext then for theWindowN := info^.PicNum+1 to nPics do if theWindow = nil then begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then theWindow := PicWindow[theWindowN]; end; if theEnum = kAEPrevious then for theWindowN := info^.PicNum-1 downto nPics do if theWindow = nil then begin theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if (theInfo^.StackInfo <> nil) then theWindow := PicWindow[theWindowN]; end; end end ELSE IF keyForm = formPropertyID THEN begin theError := LongFromDesc(keyData, theID); if (theError = noErr) then for iLoop := 1 to nPics do BEGIN theInfo := pointer(WindowPeek(PicWindow[iLoop])^.RefCon); if theInfo^.PidNum = theID then theWindow := PicWindow[iLoop]; END end; IF theWindow = NIL THEN FindStackAccessor := errAENoSuchObject ELSE {create outToken that identifies the window} BEGIN MakeTokenDesc(theWindow, 'Stak', outToken); FindStackAccessor := noErr; end END; end.